<template>
  <div class="app-container">
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
      <el-form-item label="编号" prop="number">
        <el-input  v-model="form.numberNum" disabled style="width: 280px;"/>
      </el-form-item>
      <el-form-item label="登记时间" prop="entryDate">
        <el-date-picker clearable
                        v-model="form.entryDate"
                        type="datetime"
                        style="width: 280px;"
                        :disabled='isdisabled'
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="请选择登记时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="资产类型" prop="assetType">
        <el-select  style="width: 280px;"
                    :disabled='isdisabled'
                    v-model="form.assetType" placeholder="请选择" clearable>
          <el-option
            v-for="item in dict.type.asset_type"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="资产编码" prop="assetCode">
        <el-select
                   :disabled='isdisabled'
                   style="width: 280px;" v-model="form.assetCode"
                   placeholder="请选择" clearable>
          <el-option
            v-for="item in codeList"
            :key="item"
            :label="item"
            :value="item">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="物品名称" prop="productName">
        <el-select :disabled='isdisabled'
                   style="width: 280px;" v-model="form.productName" placeholder="请选择" clearable>
          <el-option
            v-for="item in productList"
            :key="item"
            :label="item"
            :value="item">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="数量(个)" prop="wareNum">
        <el-input style="width: 280px;"
                  @input="form.wareNum=form.wareNum.replace(/\D|^0/g,'')"
                  v-model="form.wareNum" :disabled='isdisabled' placeholder="请输入数量" />
      </el-form-item>
      <el-form-item label="办理人" prop="transactor">
        <el-input style="width: 280px;" v-model="form.transactor" :disabled='isdisabled' placeholder="请输入办理人" />
      </el-form-item>
      <el-form-item label="库存剩余(个)" v-if="form.leaveCount" prop="leaveCount">
        <el-input style="width: 280px;"
                  @input="form.leaveCount=form.leaveCount.replace(/\D|^0/g,'')"
                  v-model="form.leaveCount"
                  disabled placeholder="请输入库存剩余" />
      </el-form-item>
      <el-form-item label="备注" prop="remarks">
        <el-input :disabled='isdisabled' v-model="form.remarks" type="textarea" placeholder="请输入内容" />
      </el-form-item>
      <el-form-item label="附件">
        <file-upload v-model="form.attachment" :is-disabled='isdisabled'/>
      </el-form-item>
    </el-form>
      <div v-show="parentTaskId==null" class="dialog-footer" style="text-align:center">
          <el-button :loading="buttonLoading" size="small" type="info" @click="submitCallback">关闭</el-button>
          <el-button :loading="buttonLoading" size="small" type="primary" @click="submitForm" v-if="confirmVisible">提交</el-button>
      </div>
      <!-- 工作流开始 -->
      <verify ref="verifyRef"
              :componentName="componentName"
              :taskId="taskId" @submitCallback="submitCallback"
              :taskVariables="taskVariables" :sendMessage="sendMessage"></verify>
  </div>
</template>

<script>
import { getAdminUse } from "@/api/oa/adminUse";
import verify from "@/components/Process/Verify";
import {parseTime} from "@/utils/ruoyi";
export default {
  dicts: ['act_status','asset_type'],
  name: "AdminUseForm",
  components: {
      verify
  },
  props: {
      businessKey: String, // 业务唯一标识
      parentTaskId: String, // 父级任务id
      taskId: String, // 任务id
      confirmVisible:{
          type: Boolean,
          default: true
      }
  },
  data() {
    return {
      componentName:"办公用品领用审批",
      isdisabled:true,
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 表单参数
      form: {},
        projectNameList:[],
      // 表单校验
      rules: {
        entryDate: [
          { required: true, message: "登记时间不能为空", trigger: "blur" }
        ],
        wareName: [
          { required: true, message: "物品名称不能为空", trigger: "blur" }
        ],
        standard: [
          { required: true, message: "规格不能为空", trigger: "blur" }
        ],
        wareNum: [
          { required: true, message: "数量不能为空", trigger: "blur" }
        ],
        transactor: [
          { required: true, message: "办理人不能为空", trigger: "blur" }
        ],
        inventorySurplus: [
          { required: true, message: "库存剩余不能为空", trigger: "blur" }
        ],
      },
        taskVariables: undefined,
        //消息提醒
        sendMessage: {},
        processKey: 'oa_admin_use',
        productList:[],
        codeList:[],
    };
  },
  watch: {
      businessKey: {
          immediate: true, // 很重要！！！
          handler (newVal) {
              if(newVal) {
                  this.getById()
              }
          }
      }
  },
  methods: {
    submitCallback(){
        this.$emit("closeForm")
    },
    async getById() {
      const {data} = await getAdminUse(this.businessKey)
      this.form = data;
      if (data.actBusinessStatus.createTime){
            this.form.numberNum=this.processKey + '@' + parseTime(data.actBusinessStatus.createTime, '{y}{m}{d}{h}{i}{s}')
        }
    },
    /** 提交按钮 */
    submitForm() {
        getAdminUse(this.businessKey).then(response => {
            this.taskVariables = {
                entity: response.data,
            };
          this.sendMessage = {
            title: "办公用品入库领用提醒",
            messageContent: this.$store.state.user.nickName + "审批通过了办公用品领用审批"
          };
        });
        this.$refs.verifyRef.visible = true
        this.$refs.verifyRef.reset()
    },
  }
};
</script>
<style scoped>
    /* 设置滚动条宽度和高度 */
    ::v-deep .el-table__body-wrapper::-webkit-scrollbar {
        width: 8px; /* 横向滚动条 */
        height: 8px; /* 纵向滚动条 必写 */
    }
    /* 设置滚动条样式 */
    ::v-deep .el-table__body-wrapper::-webkit-scrollbar-thumb {
        background-color: #dde;
        border-radius: 3px;
    }
    #selectForm >>> .el-form-item__label {
        font-size: 12px;
    }
    ::v-deep .bjsm .el-form-item__content{
        width: calc(100% - 130px) !important;
    }
</style>
